package com.thinking.in.spring.ioc.dependency.source;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author : zjj
 * @date : 2022/1/26 8:49
 */
public class ResolvableDependencySourceDemo {

    @Autowired
    private String username;

    public static void main(String[] args) {
        AnnotationConfigApplicationContext beanFactory = new AnnotationConfigApplicationContext();

        beanFactory.register(ResolvableDependencySourceDemo.class);

        // 回调是 在 refresh 中才触发的
        beanFactory.addBeanFactoryPostProcessor((listableBeanFactory)->{
            // 注册 Resolvable Dependency ,这个只能用于依赖注入，并且是通过类型的依赖注入(没有提供名称)
            // 不能用户依赖查找 ，会报 NoSuchBeanException
            listableBeanFactory.registerResolvableDependency(String.class,"hello,workd");
        });

        beanFactory.refresh();

        System.out.println(beanFactory.getBean(ResolvableDependencySourceDemo.class).username);


        beanFactory.close();
    }
}
